package Exercise;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class Exercise02 {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        Car benchi = new Car("迈巴赫", 10000000);
        Car bmw = new Car("宝马7系", 980000);
        arrayList.add(benchi);
        arrayList.add(bmw);
        System.out.println(arrayList);

        arrayList.remove(0);
        System.out.println(arrayList);

        //Contains查看是否存在
        System.out.println(arrayList.contains(benchi));

        System.out.println(arrayList.size());

        System.out.println(arrayList.isEmpty());

        arrayList.add(benchi);
        System.out.println(arrayList);


        //arrayList.removeAll(arrayList);//相当于清空

        //遍历
        for (Object car :arrayList) {
            System.out.println(car);
        }

        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object car = iterator.next();
            System.out.println(car);
        }


    }
}
class Car{
    private String name;
    private double price;

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return name + "_" + price;
    }
}
